package com.link.linkupjavaweb.controller.user;

import com.link.linkupjavaweb.common.Constants;
import com.link.linkupjavaweb.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * 用户主页Controller
 */
@Controller
@RequestMapping("/user")
public class UserHomeController {
    
    /**
     * 用户主页
     */
    @GetMapping("/home")
    public String home(HttpSession session, Model model) {
        User user = (User) session.getAttribute(Constants.SESSION_USER);
        if (user == null) {
            return "redirect:/user/login";
        }
        model.addAttribute("user", user);
        return "user/home";
    }
}

